/*
 * @Author: your name
 * @Date: 2021-10-29 16:36:48
 * @LastEditTime: 2022-06-12 18:12:01
 * @LastEditors: yan_hai_dong 891236760@qq.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \app\src\directive\focus.js
 */
import {
    Message
} from "element-ui"
export default {
    inserted: (el, binding) => {
        el.onclick = () =>
            hand(el, binding)
    },
    update: (el, binding) => {
        el.onclick = () => hand(el, binding)
    }
}

// 事件处理
function hand(el, binding) {
    if (binding.value)
        copy(binding.value)
    else
        copy(el.innerText)
}

// 复制到剪贴板
function copy(val) {
    var input = document.createElement("input");
    input.value = val;
    document.body.appendChild(input);
    input.select(); // 选择对象
    if (document.execCommand("Copy")) {
        Message({
            message: '复制成功',
            type: 'success'
        });
        input.className = "oCopy";
        input.style.display = "none";
        setTimeout(() => {
            input.remove();
        }, 1000);
    }
}